# Import the functions. See http://www.codeplex.com/PSHyperv
. hyperv\hyperv.ps1

# Create a new VM with the name DentalDev
$vmDir = Get-Location
$vmName = "DentalDev"
$vhdName = $vmName + ".vhd"
$cpuCount = 4
$memory = 4gb
$vhdSize = 40gb
$vhdPath = Join-Path $vmDir $vhdName

$vmlogin = "dentaldev-usr"
$vmpass = "Belgium01@foo"
$vmshare = "ddevfiles"

$windowsIsoPath = Join-Path $vmDir "en_windows_xp_professional_with_service_pack_3_x86_cd_x14-80428.iso"

$bootDiskDir = "winboot"
$bootDisk = "winboot.vfd"

Write-Output "Setting up the user and file share"
net user $vmlogin /delete
net user $vmlogin $vmpass /add

net share $vmshare /DELETE
net share "$vmshare=$vmDir" "/GRANT:$vmlogin,FULL"

Write-Output "Creating the boot floppy"
rmdir $bootDiskDir -recurse
del $bootdisk
del floppy
mkdir $bootDiskDir
copy unattend.txt $bootDiskDir\winnt.sif
bfi\bfi.exe -v -f=floppy $bootDiskDir
mv floppy $bootDisk

Write-Output "Removing any existing VM's..."

del $vhdPath

Write-Output "Creating $vmName with $vhdSize hard disk ($vhdPath), $cpuCount processors and $memory memory."

New-VM $vmName

Set-VMmemory $vmName $memory
Set-VMCPUCount $vmName $cpuCount
Add-VMNic $vmName (choose-VMSwitch)

Write-Output "Creating and mounting hard drive."
$jobId = New-VHD $vhdPath $vhdSize   
test-wmijob $jobID -wait
Add-VMDrive $vmName 0 0
Add-VMDISK $vmname 0 0 $vhdPath

Write-Output "Creating and mouting DVD."
Add-VMDrive $vmName 1 0 -DVD
Add-VMDisk $vmName 1 0 $windowsIsoPath -DVD

Write-Output "Starting the VM."
Start-VM $vmName